import { _decorator, Component, Enum, Label, Node, Toggle, Vec3 } from 'cc';
import { Mode, ModeName, ModeType } from '../enum/Mode';
import { GameMgr } from '../manager/GameMgr';
import { TransMgr } from '../manager/TransMgr';
import { UIMgr } from '../manager/UIMgr';
import { UI } from '../enum/UI';
import { GameUtil } from '../util/GameUtil';
const { ccclass, property } = _decorator;

@ccclass('UIItem/MainItem')
export class MainItem extends Component {

    @property(Label)
    public numLab: Label = null;



    protected onLoad(): void {
        // this.btnStart = this.node.getChildByName('BtnStart')
        // this.btnUnlock = this.node.getChildByName('BtnUnlock')

        // GameMgr.mode = GameUtil.getTodayMode();

    }

    protected start(): void {
        this.updateState()
    }

    private updateState(): void {

    }

    protected async onBtnStartClick(ind:number) {
        // if (GameMgr.getIsPassToday() && !GameMgr.getIsTest()){
        //     UIMgr.open(UI.Toast, '今天已通关，请明天再来闯关')
        //     return;
        // } 
        //GameMgr.resetGameLevle();
        // await TransMgr.Inst.fadeIn()
        // TransMgr.Inst.fadeOut()
        UIMgr.close(UI.Main)
        // GameMgr.mode = this.mode
        GameMgr.startGame()
    }

    protected onBtnUnlockClick(): void {
        this.updateState()
    }

    onBtnClickHandler(eve:Event, str:string){
        if (str == "rank"){
            UIMgr.open(UI.RankView);
        }else if (str.includes("btn")){
            let ind =  Number(str.slice(-1));
            console.log("开始模式：" + ind);

            GameMgr.mode = Mode.tp;
            GameMgr.modeType = ind-1;

            if (GameMgr.modeType == ModeType.caipingQinglv || GameMgr.modeType == ModeType.caipingDashi){
                UIMgr.open(UI.ShopView);
            }else{
                this.onBtnStartClick(ind)
            }
        }
    }

}


